home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / exec.arc / EXECL.C < prev   
Text File  |  1985-07-23  |  8KB  |  249 lines

  1. /*
  2. This is a simple implementation of execl() for MS-DOS 2.0/CI-C86 v2.04B.  See
  3. comments for details.  If someone knows details about what exactly FCB1 and
  4. FCB2 are used for, I would be interested in knowing.  Would they serve any
  5. purpose with DOS 2.0 calls?  Are they stdin/stdout?  Thanks, and have fun!
  6.  
  7. The file format is CI's ARCHive format.  If you don't have that, '-ARCHIVE-'
  8. starts lines separating files.  Just split them there with an editor (and get
  9. rid of the line).  The file name and size is also on the separator line.
  10.  
  11. Questions, comments, flames, vegetables, etc. can be sent to Alan Batie via:
  12.  
  13.  
  14.          >>----->>-------------( Nathan C. Myers )-----------------\
  15.                /                                                    |
  16.               |  ...!decvax!tektronix!ogcvax!hp-pcd!orstcs!nathan   |
  17.               |           nathan.oregon-state@RAND-RELAY            |
  18.                \___________________________________________________/
  19.  
  20.  
  21. --------------------------------Tear off here---------------------------------
  22. -ARCHIVE- exec.c 1395
  23. /*
  24.  *  File name:          exec.c
  25.  *
  26.  *  Belongs to:         System utilities
  27.  *  Description:        Executes a program specified on command line.  Mostly
  28.  *                      used as demonstation of execl() function call.
  29.  *
  30.  *  Version:            0.0
  31.  *  History:            None
  32.  *  Last change:        3/3/84 - Original code.  Alan Batie
  33.  *
  34.  *  Nathan C. Myers:
  35.  *      UUCP:           ...!decvax!tektronix!orstcs!nathan
  36.  *      ARPANET:        nathan.oregon-state@RAND-RELAY
  37.  */
  38.  
  39. /*      SET RUN TIME DEFAULT VALUES
  40. */
  41.  
  42. int _MAXFMEM=0x200;             /* MAXIMUM STACK+HEAP REQUIRED */
  43. int _MINFMEM=0x50;              /* MINIMUM STACK+HEAP REQUIRED */
  44. int _MINRMEM=0;                 /* RESERVED FOR COMMAND.COM AT TOP OF MEM */
  45.                                 /*   Not necessary, as memory limit set low  */
  46. int _STAKMEM=64;                /* MIN STACK IN SBRK BEFORE REFUSING ALLOC */
  47.  
  48. #include "stdio.h"
  49.  
  50. /*
  51.  *  This program can only be compiled under big model, although small could
  52.  *  be used if execl() set up for small model.  Other bugs: CI-C86 doesn't
  53.  *  recognize quoted strings in the command l)w$ processor.  Will fix this
  54.  *  Real Soon Now.
  55.  */
  56.  
  57. /*  exec <prog> [ <command line> ]  */
  58.  
  59. main(argc, argv)
  60.         int argc;
  61.         char *argv[];
  62.         {
  63.         int err;
  64.  
  65.         if (argc == 1)
  66.                 {
  67.                 fputs("exec: usage exec <prog> [ <com. line> ]\n", stderr);
  68.                 exit(255);
  69.                 }
  70.  
  71.         if (argc >= 3)
  72.                 {
  73.                 err = execl(argv[1], argv[2]);
  74.                 }
  75.         else
  76.                 {
  77.                 err = execl(argv[1], " ");
  78.                 }
  79.  
  80.         if (err != 0)
  81.                 {
  82.                 sys_err(err);
  83.                 }
  84.         }
  85. -ARCHIVE- execl.c 1523
  86. /*
  87.  *  File name:          execl.c
  88.  *
  89.  *  Belongs to:         System extended library
  90.  *  Description:        Executes another program as though a subroutine.
  91.  *
  92.  *  Version:            0.0
  93.  *  History:            None
  94.  *  Last change:        3/3/84 - Original code.  Alan Batie
  95.  *
  96.  *  Nathan C. Myers:
  97.  *      UUCP:           ...!decvax!tektronix!orstcs!nathan
  98.  *      ARPANET:        nathan.oregon-state@RAND-RELAY
  99.  */
  100.  
  101. /*  This program can only be compiled under big model, small could be used
  102.  *  if pointers passed to exec() were built for large model - see CI docs.
  103.  *  The _default.c vars must be set by the program, so enough space is
  104.  *  available for new program.  Requires CI-C86 2.04B or better.  Previous
  105.  *  versions did not fully correct MS-DOS 2.0 bugs, and don't work.  (Not
  106.  *  sure when it started working - 2.03x *might* work.)  Other brands will
  107.  *  work if they have a correct (with bug spray) call to function 4B.
  108.  */
  109.  
  110. #include "stdio.h"
  111.  
  112. execl(path, arg_str)
  113.         char *path;
  114.         char *arg_str;
  115.         {
  116.         struct parm_struct
  117.                 {
  118.                 int env_str_seg;
  119.                 char *com_line;
  120.                 char *fcb1;
  121.                 char *fcb2;
  122.                 } parm_block;
  123.  
  124.         int err;
  125.  
  126. /*  Initialize parameter block  */
  127.  
  128.         parm_block.env_str_seg =
  129.         parm_block.fcb1 =
  130.         parm_block.fcb2 = NULL;
  131.  
  132. /*  Change format of string to [count][string]  */
  133.  
  134.         parm_block.com_line = alloc(strlen(arg_str) + 2);
  135.         *parm_block.com_line = strlen(arg_str);
  136.         strcpy(parm_block.com_line + 1, arg_str);
  137.  
  138. /*  Go do it! (last parm = 0 means load and execute, 3 = just load)  */
  139.  
  140.         err = loadexec(path, &parm_block, 0);
  141.         }
  142. -ARCHIVE- sys_err.c 1880
  143. /*
  144.  *  File name:          sys_err.c
  145.  *
  146.  *  Belongs to:         System library
  147.  *  Description:        Displays error message based on error code returned
  148.  *                      from system call.
  149.  *
  150.  *  Version:            1.0
  151.  *  Last change:        None - original code
  152.  *  Author:             Alan Batie
  153.  */
  154.  
  155. #include "stdio.h"
  156. #include "stdext.h"
  157.  
  158. sys_err(err_code)
  159.         int err_code;
  160.         {
  161.         char buf[10];
  162.  
  163.         switch (err_code)
  164.                 {
  165.                 case 1:
  166.                         fputs("\nInvalid function number\n", STDERR);
  167.                         break;
  168.  
  169.                 case 2:
  170.                         fputs("\nFile not found\n", STDERR);
  171.                         break;
  172.  
  173.                 case 3:
  174.                         fputs("\nPath not found\n", STDERR);
  175.                         break;
  176.  
  177.                 case 4:
  178.                         fputs("\nToo many open files\n", STDERR);
  179.                         break;
  180.  
  181.                 case 5:
  182.                         fputs("\nAccess denied\n", STDERR);
  183.                         break;
  184.  
  185.                 case 6:
  186.                         fputs("\nInvalid handle\n", STDERR);
  187.                         break;
  188.  
  189.                 case 7:
  190.                         fputs("\nMemory control blocks destroyed\n", STDERR);
  191.                         break;
  192.  
  193.                 case 8:
  194.                         fputs("\nInsufficient memory\n", STDERR);
  195.                         break;
  196.  
  197.              )0!case 9:
  198.                         fputs("\nInvalid memory block address\n", STDERR);
  199.                         break;
  200.  
  201.                 case 10:
  202.                         fputs("\nInvalid environment\n", STDERR);
  203.                         break;
  204.  
  205.                 case 11:
  206.                         fputs("\nInvalid format\n", STDERR);
  207.                         break;
  208.  
  209.                 case 12:
  210.                         fputs("\nInvalid access code\n", STDERR);
  211.                         break;
  212.  
  213.                 case 13:
  214.                         fputs("\nInvalid data\n", STDERR);
  215.                         break;
  216.  
  217.                 case 14:
  218.                         fputs("\nUnknown error code ", STDERR);
  219.                         itoa(err_code, buf);
  220.                         fputs(buf, STDERR);
  221.                         fpu:>2e", STDERR);
  222.                         break;
  223.  
  224.                 case 15:
  225.                         fputs("\nInvalid drive was specified\n", STDERR);
  226.                         break;
  227.  
  228.                 case 16:
  229.                         fputs("\nAttempted to remove current directory\n", STDERR)
  230.                         break;
  231.  
  232.                 case 17:
  233.                         fputs("\nNot same device\n", STDERR);
  234.                         break;
  235.  
  236.                 case 18:
  237.                         fputs("\nNo more files\n", STDERR);
  238.                         break;
  239.  
  240.                 default:
  241.                         fputs("\nUnknown error code ", STDERR);
  242.                         itoa(err_code, buf);
  243.                         fputs(buf, STDERR);
  244.                         fputs("\n", STDERR);
  245.                         break;
  246.                 }
  247.         }
  248. */
  249.